]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
iconGrid: Only recreate icons when needed
authorJasper St. Pierre <jstpierre@mecheye.net>
Sat, 1 Dec 2012 01:35:04 +0000 (20:35 -0500)
committerJasper St. Pierre <jstpierre@mecheye.net>
Fri, 14 Dec 2012 02:35:05 +0000 (21:35 -0500)
Recreating icons on every style change -- like hover, can have
disasterous effects. Not only is the quick creation/destruction of
the actors bad, but adding/removing actors at runtime queues many
relayouts, which makes the whole system slower as a lot of unnecessary
reallocations are figured out.

While an optimization was here before, it was broken because it
broke high-contrast themes. Connect explicitly to the texture cache
to know when the icon theme has changed, instead of removing a valuable
optimization.

https://bugzilla.gnome.org/show_bug.cgi?id=672941

js/ui/iconGrid.js

index 04b8caf69b7bb7530b91b8aa2b3e6daa326c4725..2b63865315d439a63d520cfeb2b6f7c2dba0b93b 100644 (file)
@@ -23,6 +23,8 @@ const BaseIcon = new Lang.Class({
         this.actor._delegate = this;
         this.actor.connect('style-changed',
                            Lang.bind(this, this._onStyleChanged));
+        this.actor.connect('destroy',
+                           Lang.bind(this, this._onDestroy));
 
         this._spacing = 0;
 
@@ -52,6 +54,9 @@ const BaseIcon = new Lang.Class({
         this._setSizeManually = params.setSizeManually;
 
         this.icon = null;
+
+        let cache = St.TextureCache.get_default();
+        this._iconThemeChangedId = cache.connect('icon-theme-changed', Lang.bind(this, this._onIconThemeChanged));
     },
 
     _allocate: function(actor, box, flags) {
@@ -146,7 +151,22 @@ const BaseIcon = new Lang.Class({
             size = found ? len : ICON_SIZE;
         }
 
+        if (this.iconSize == size && this._iconBin.child)
+            return;
+
         this._createIconTexture(size);
+    },
+
+    _onDestroy: function() {
+        if (this._iconThemeChangedId > 0) {
+            let cache = St.TextureCache.get_default();
+            cache.disconnect(this._iconThemeChangedId);
+            this._iconThemeChangedId = 0;
+        }
+    },
+
+    _onIconThemeChanged: function() {
+        this._createIconTexture(this.iconSize);
     }
 });